<?php
namespace Admin\Controller;
use Think\Controller;
class ShaituController extends BaseController{
    public function shaitulist(){
    	/*尹京华--显示晒图方法*/
    	$shaitumodel = M('shaitu');
        $pageSize=10;//每页显示的数据个数
        $records=$shaitumodel->count(); //查询数据表中数据的总个数
        $Page = new \Think\Page($records,$pageSize);//实例化分页类，传入总数和每页显示的数量
        $list=$shaitumodel->order('shaitu_id asc')->limit($Page->firstRow,$pageSize)->select();//进行分页数据查询
        $page1=$Page->show();//分页显示输出
        $this->assign(array('shaitu'=>$list,'page1'=>$page1));//用数组的方式赋值数据集，赋值分页输出
        $this->display();//输出模板
    }
    public function shaitudel($shaitu_id){
    	/*尹京华--删除晒图方法*/
        $shaitumodel = M('shaitu');
        $shaitu=$shaitumodel->where("shaitu_id=$shaitu_id")->find();
        
      if ($shaitu["shaitu_pic"]=="default.jpg") 
        {

        }
            else
        {
                unlink(realpath("./Public/pic/".$shaitu["shaitu_pic"]));
        }

        if ($shaitu["shaitu_pic1"]=="default.jpg") 
        {

        }
            else
        {
                unlink(realpath("./Public/pic/".$shaitu["shaitu_pic1"]));
        }

        if ($shaitu["shaitu_pic2"]=="default.jpg") 
        {

        }
            else
        {
                unlink(realpath("./Public/pic/".$shaitu["shaitu_pic2"]));
        }
        if (false !== $shaitumodel->where("shaitu_id=$shaitu_id")->delete()) {
            $this->success('删除成功！',U('Shaitu/shaitulist'),3);
        } else {
            $this->error('删除失败 ');
        }
        
    }

    public function sshaitu($shaitu_explain){
        /*尹京华--搜索晒图方法*/
        $shaitumodel =M('shaitu');
        /*$map['shaitu_explain']=array('like',"%'$shaitu_explain'%");
        $shaitu=$shaitumodel->where($map)->order('shaitu_id asc')->select();*/
        $shaitu=$shaitumodel->query("select * from shaitu where shaitu_explain LIKE '%$shaitu_explain%'");
        $this->shaitu=$shaitu;
        $this->display(); 
    } 

    public function shaitudetail($shaitu_id,$uid){
        /*尹京华--晒图详情方法*/
        $shaitumodel =M('shaitu');
        $shaitu=$shaitumodel->where("shaitu_id=$shaitu_id")->find();
        $this->shaitu=$shaitu;
        /**/
        $usermodel=M('user');
        $user=$usermodel->where("uid=$uid")->find();
        $this->user=$user;
        /**/
        $commentsmodel=M('comments');
        $comments=$commentsmodel->where("shaitu_id=$shaitu_id")->select();
        $this->comments=$comments;
        $this->display();
    }

    public function shaitustate($shaitu_id,$shaitu_state){
        $shaitumodel=M('shaitu');
        if($shaitu_state==0)
        { $shaitumodel->shaitu_state=1;}
        else
        { $shaitumodel->shaitu_state=0;}
        if(false!==$shaitumodel->where("shaitu_id=$shaitu_id")->save()){
            $this->success("状态修改成功！",U("Shaitu/shaitulist"));  
        }
        else{
             $this->error('状态修改失败'); 
        }
    }
}
?>